<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use dosamigos\datetimepicker\DateTimePicker;

/* @var $this yii\web\View */
/* @var $model common\models\SuperTry */
/* @var $form yii\widgets\ActiveForm */
?>

<style>
.field-supertry-recommend_time .input-group{width:300px;}
.field-supertry-position{width:300px;}
</style>
<div class="super-try-form">

    <?php $form = ActiveForm::begin(['id' => 'form1']); ?>

    <?= $form->field($model, 'position')->dropDownList(['1'=>'展位1','2'=>'展位2','3'=>'展位3',]) ?>

    <?= $form->field($model, 'product')->textInput() ?>

    <?= $form->field($model, 'recommend_time')->widget(DateTimePicker::className(), 
        [
        'template'=>"{input}{reset}{button}",
        'clientOptions' => [
            'autoclose' => true,
            'linkFormat' => 'yyyy-MM-dd', // if inline = true
            //'format' => 'yyyy-mm-dd', // if inline = false
            'todayBtn' => true,
            'pickerPosition'=>"bottom-left",
            'language'=>'zh-CN',
            'minView'=>'hour'
        ]    
    ])  ?>


    <div class="form-group">
        <?= Html::input('hidden', 'form_check', $model->isNewRecord ? 0 : 1, ['id'=>'form_check']); ?>
        <?= $model->isNewRecord ? $form->field($model, 'add_time')->hiddenInput(['value'=>date('Y-m-d H:i:s')])->label(false) : '' ?>
        <?= $model->isNewRecord ? $form->field($model, 'add_user')->hiddenInput(['value'=>Yii::$app->session['admin_name']])->label(false)  : '' ?>
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php $this->beginBlock('js');?>
<script>
$(function(){
    $('#supertry-product').change(function(){
           $.post("<?=Yii::$app->urlManager->createUrl('day-try/get-goods-info')?>",{product_id: $('#supertry-product').val(), rnd:Math.random()},  function(json) {
               if(json.flag == 1)
               {
                   $('#form_check').val(1);
                   return false;
               }else
               {
                   alert(json.msg);
                   $('#form_check').val(0);
                   return false;
               }
            },"json");
    });
    
    $("#form1").submit(function(){
        
        if($('#form_check').val() == 0)
        {
            alert('货品ID不存在');
            return false;  
        }
           return true;  
    });  
});

</script>
<?php $this->endBlock(); ?>